package com.uzykj.modules.blog.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author ghostxbh
 * @date 2020/7/15
 * @description
 */
public class NoteUtil {
    private static final long DEAFULT = 1;
    private static final int CODELENGTH = 8;

    /**
     * 获取最大code
     *
     * @param maxCode
     * @return
     */
    public static String getCode(String maxCode) {
        long newCode = DEAFULT;
        if (!StringUtils.isEmpty(maxCode)) {
            newCode = Long.parseLong(maxCode) + 1;
        }
        int length = Long.toString(newCode).length();
        return prexCode(length) + newCode;
    }

    private static String prexCode(int length) {
        int prexLength = CODELENGTH - length;
        StringBuilder prex = new StringBuilder();
        for (int i = 0; i < prexLength; i++) {
            prex.append("0");
        }
        return new String(prex);
    }

    public static void main(String[] args) {
        String code = getCode(null);
        System.out.println(code);
    }
}
